﻿using UnityEngine;
using UnityEngine.UI;
using ProtoBuf.Message;

namespace AutoChess
{
    public class ChessFightRecordItem : MonoBehaviour
    {
        [SerializeField]
        private Button mLookBtn;
        [SerializeField]
        private ChessFightRecordPlayerInfo mAttPlayerInfo;
        [SerializeField]
        private ChessFightRecordPlayerInfo mDefPlayerInfo;

        private long mFightId;

        public void Init(AutoChessFightRecordInfo recordInfo)
        {
            mFightId = recordInfo.fightId;
            mLookBtn.AddOnClickListener(OnClickBtn);
            if (recordInfo.attPlayer != null)
            {
                mAttPlayerInfo.Init(recordInfo.attPlayer, true);
            }
            else
            {
                ExLog.LogError("自走棋战斗回放，服务器返回攻方角色信息为空");
            }
            if (recordInfo.defPlayer != null)
            {
                mDefPlayerInfo.Init(recordInfo.defPlayer, false);
            }
            else
            {
                ExLog.LogError("自走棋战斗回放，服务器返回守方角色信息为空");
            }
        }

        private void OnClickBtn()
        {
            AutoChessManager.Ins.SendCSAutoChessGetFightReplay(mFightId);
        }
    }
}